from typing import List

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        if len(nums) > 0:
            h, m, t = 0, 0, len(nums) - 1
            if nums[h] != target:           # 找左端点
                m = len(nums) - 1
                while h != m:
                    s = (h + m) // 2
                    if nums[s] < target:
                        h = s + 1
                    else :
                        m = s
            if nums[h] == target:           # 保证数字存在，然后找右端点
                if nums[t] != target:
                    while m != t:
                        s = (m + t + 1) // 2
                        if nums[s] > target:
                            t = s - 1
                        else:
                            m = s
                return t-h+1
        return 0
                    


if __name__ == '__main__':
    c = Solution()
    print(c.search([5,7,7,8,8,10], 11))